package typingballoon;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.media.Player;
import javax.microedition.midlet.*;

/**
 * @author USER
 */
public class TypingBalloonMIDlet extends MIDlet {

    public static int CLICKED = 0;
    protected Display display;      //reference to display
    //private Command cmdExit;
    //canvas
    private MenuCanvas menuCanvas;
    private TypingCanvas typingCanvas;
    private TypingCanvas640 typingCanvas640;
    private SplashScreen splash;
    //private Player player = null;
    public static Font SMALL_PLAIN_FONT;
    public static Font SMALL_BOLD_FONT;
    public static Font LARGE_BOLD_FONT;

    public TypingBalloonMIDlet() {
        SMALL_PLAIN_FONT = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL);
        SMALL_BOLD_FONT = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_SMALL);
        LARGE_BOLD_FONT = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_LARGE);

        display = Display.getDisplay(this);
        splash = new SplashScreen(this);
        menuCanvas = new MenuCanvas(this, display);
    }

    public void startApp() {
        //showMenuCanvas();
        if (display == null) {
            display = Display.getDisplay(this);
        }
        display.setCurrent(splash);
        splash.start();

        //setSoundDuar();
        //showTypingCanvas();
        //showTypingCanvas640();
    }
//    }

    public void pauseApp() {
        //notifyPaused();
    }

    public void destroyApp(boolean unconditional) {
    }

    public void exit() {
        menuCanvas.stop();

        destroyApp(true);
        notifyDestroyed();
    }

    public void showMenuCanvas() {
        CLICKED = 0;

        if (typingCanvas != null) {
            typingCanvas.stop();
        }
        typingCanvas = null;
        if (typingCanvas640 != null) {
            typingCanvas640.stop();
        }
        typingCanvas640 = null;

        menuCanvas.start();
        display.setCurrent(menuCanvas);
    }

    public void showTypingCanvas() {
        if (CLICKED < 1) {
            CLICKED = CLICKED + 1;
            menuCanvas.stop();
            
            typingCanvas = new TypingCanvas(this);
            display.setCurrent(typingCanvas);
            typingCanvas.start();
        }
    }

    public void showTypingCanvas640() {
        if (CLICKED < 1) {
            CLICKED = CLICKED + 1;
            typingCanvas640 = new TypingCanvas640(this);
            //menuCanvas.stop();
            //typingCanvas640.stop();
            if (typingCanvas640 != null) {
                display.setCurrent(typingCanvas640);
                typingCanvas640.start();
            }
        }
    }

    /*
    private void setSoundDuar() {
        try {
            InputStream in = getClass().getResourceAsStream("/bang.wav");
            player = Manager.createPlayer(in, "audio/x-wav");
            player.setLoopCount(1);
            
        } catch (Exception e) {
        }
    }

    public void playSoundDuar() {
        try {
            player.stop();
            player.start();
        } catch (MediaException ex) {
        }
    }
     * 
     */
}
